var common = require('../../lib/common.js');
var url = require('../../config/url.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    user: {

    },
    count: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo();

    this.updateMessageNum();

    setInterval(() => {
      this.updateMessageNum();
    }, 1000);
  },
  getUserInfo() {
    common.post(url.getUserInfo, {}, (data) => {
      this.setData({ user: data });
    });
  },
  onPullDownRefresh() {
    this.getUserInfo();
    wx.stopPullDownRefresh();
  },

  updateMessageNum() {
    let data = wx.getStorageSync('unreadMessageNum');
    let chat = data['chat'];
    let message = data['message'];

    let count = chat + message;
    this.setData({ count })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})